package com.sky.checkutil.domain;

import com.google.common.collect.Lists;
import com.sun.javadoc.ClassDoc;
import lombok.Builder;
import lombok.Data;

import java.util.List;

/**
 * 代码检测参数
 *
 * @author: hjy
 * @create: 2023-12-28 11:28
 **/
@Data
@Builder
public class CheckParam {

    /**
     * 检测文件夹路径
     */
    public String folderPath;

    /**
     * 排除检测文件夹路径
     */
    @Builder.Default
    public List<String> excludeFolder = Lists.newArrayList(".idea",
            ".idea",
            "disconf",
            "logs",
            "script",
            "span",
            "target",
            "test",
            "resources");

    /**
     * 是否检测下级文件夹
     */
    @Builder.Default
    public Boolean checkBelowFolder = false;

    /**
     * 检测的文件后缀
     */
    @Builder.Default
    public List<String> checkFileSuffix = Lists.newArrayList(".java");

    /**
     * 导出excel文档路径
     */
    @Builder.Default
    public String exportPath = "D:\\检测结果文档.xlsx";

    /**
     * 检测结果
     */
    @Builder.Default
    public String result = "不通过";

    /**
     * 检测类类型：class、interface等
     */
    @Builder.Default
    public String classType = ClassType.INTERFACE;

    /**
     * 检测类型
     *
     * @param classDoc
     * @return
     */
    public Boolean classDocCheck(ClassDoc classDoc) {
        ClassType classType = new ClassType();
        return classType.check(classDoc);
    }

    class ClassType {
        /**
         * 类
         */
        private static final String CLASS = "class";

        /**
         * 接口
         */
        private static final String INTERFACE = "interface";

        /**
         * 检测
         *
         * @param classDoc
         * @return
         */
        public Boolean check(ClassDoc classDoc) {
            Boolean flag;
            switch (classType) {
                case CLASS:
                    flag = classDoc.isClass();
                    break;
                case INTERFACE:
                    flag = classDoc.isInterface();
                    break;
                default:
                    flag = true;
                    break;
            }
            return flag;
        }
    }
}
